﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lab1
{
    public partial class Form1 : Form
    {
        string A;
        string B;
        string C;
        string D;
        string Q;
        string E;
        string W;
        string T;
        string Checker;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            A = ""; B = ""; C = ""; D = ""; Q = ""; E = ""; W = ""; T = "";
            listBox1.Items.Clear();
            listBox2.Items.Clear();
            A = "A = 0" + textBox2.Text + ", " + "1" + textBox1.Text;
            B = "B = 0" + textBox3.Text + ", " + "1" + textBox4.Text;
            C = "C = 0" + textBox5.Text + ", " + "1" + textBox6.Text;
            D = "D = 0" + textBox7.Text + ", " + "1" + textBox8.Text;
            listBox1.Items.Add(A);
            listBox1.Items.Add(B);
            listBox1.Items.Add(C);
            listBox1.Items.Add(D);
            PrGr("A");
            PrGr("B");
            PrGr("C");
            PrGr("D");
            listBox2.Items.Add(Q);
            listBox2.Items.Add(E);
            listBox2.Items.Add(W);
            listBox2.Items.Add(T);
        }
        public void PrGr(string St)
        {       
            bool f = false;
            string l = St + "=";
            if (textBox2.Text == St)
            {
                if (f) l += ", ";
                l += "A" + "0 ";
                f = true;
            }
            if (textBox1.Text == St)
            {
                if (f) l += ", ";
                l += "A" + "1 ";
                f = true;
            }
            if (textBox3.Text == St)
            {
                if (f) l += ", ";
                l += "B" + "0 ";
                f = true;
            }
            if (textBox4.Text == St)
            {
                if (f) l += ", ";
                l += "B" + "1 ";
                f = true;
            }
            if (textBox5.Text == St)
            {
                if (f) l += ", ";
                l += "C" + "0 ";
                f = true;
            }
            if (textBox6.Text == St)
            {
                if (f) l += ", ";
                l += "C" + "1 ";
                f = true;
            }
            if (textBox7.Text == St)
            {
                if (f) l += ", ";
                l += "D" + "0 ";
                f = true;
            }
            if (textBox8.Text == St)
            {
                if (f) l += ", ";
                l += "D" + "1 ";
                f = true;
            }
            if (f) listBox2.Items.Add(l);


        }

        private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Checker = "";
            int nstate = 0;
            const int stateA = 0;
            const int stateB = 1;
            const int stateD = 2;
            int g = 0;
            int i;
            Checker = textBox9.Text;
            for (i = 0; i <= Checker.Length; i++)
            {
                switch (nstate)
                {
                    case stateA:
                        if (((i + 1) < Checker.Length) && (Checker[i] == '0') && (Checker[i + 1] == '0'))
                        {

                            g++;
                            i++;
                        }
                        else
                        {
                            nstate = stateB;
                            i--;
                        }
                        break;
                    case stateB:
                        if (i == Checker.Length)
                        {
                            if (g % 2 != 0)
                            {
                                nstate = stateD;
                            }
                        }
                        else
                            nstate = stateA;
                        break;
                }

            }
            if (nstate == stateD)
                textBox10.Text = "Yes";
            else
                textBox10.Text = "No";
        }


        private void button3_Click(object sender, EventArgs e)
        {
            Checker = "";
            int nstate = 0;
            const int stateD = 0;
            const int stateE = 1;
            const int stateB = 2;
            const int stateA = 3;
            const int stateQ = 4;
            string l = "iIjJkKlLmMnN";
            string rus = "йЙцЦуУкКеЕнНгГшШщЩзЗхХъЪфФыЫвВаАпПрРоОлЛдДжЖэЭяЯчЧсСмМиИтТьЬбБюЮ";
            Checker = textBox11.Text;
            int j;
            int i;
            int k;
            for (i = 0; i < Checker.Length; i++)
            {
                switch (nstate)
                {
                    case stateD:
                        for (j = 0; j < l.Length; j++)
                        {
                            if (Checker[0] == l[j])
                            {
                                nstate = stateE;
                                break;
                            }
                            else
                                nstate = stateQ;
                        }
                        break;
                    case stateE:
                        for (k = 0; k < rus.Length; k++)
                        {
                            if (Checker[i] != rus[k])
                            {
                                if (Char.IsLetter(Checker[i]) || Char.IsDigit(Checker[i]))
                                {
                                    nstate = stateB;
                                }
                                else
                                    nstate = stateQ;
                            }
                            else
                            {
                                nstate = stateQ;
                                break;
                            }
                        }
                        if(nstate==stateB)
                            i--;
                        
                        break;
                    case stateB:
                        if (i<=6)
                        {
                            nstate = stateE;
                        }
                        else
                            nstate = stateQ;  
                        break;
                }
            }
            if (nstate == stateE)
                textBox12.Text = "Yes";
            else
                textBox12.Text = "No";
        }
    }
}